package cn.iocoder.yudao.module.vos.service.pushlistconfig;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vos.controller.admin.pushlistconfig.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.pushlistconfig.PushListConfigDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vos.dal.mysql.pushlistconfig.PushListConfigMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vos.enums.ErrorCodeConstants.*;

/**
 * 名单推送配置 Service 实现类
 *
 * @author shijun
 */
@Service
@Validated
public class PushListConfigServiceImpl implements PushListConfigService {

    @Resource
    private PushListConfigMapper pushListConfigMapper;

    @Override
    public Long createPushListConfig(PushListConfigSaveReqVO createReqVO) {
        // 插入
        PushListConfigDO pushListConfig = BeanUtils.toBean(createReqVO, PushListConfigDO.class);
        pushListConfigMapper.insert(pushListConfig);

        // 返回
        return pushListConfig.getId();
    }

    @Override
    public void updatePushListConfig(PushListConfigSaveReqVO updateReqVO) {
        // 校验存在
        validatePushListConfigExists(updateReqVO.getId());
        // 更新
        PushListConfigDO updateObj = BeanUtils.toBean(updateReqVO, PushListConfigDO.class);
        pushListConfigMapper.updateById(updateObj);
    }

    @Override
    public void deletePushListConfig(Long id) {
        // 校验存在
        validatePushListConfigExists(id);
        // 删除
        pushListConfigMapper.deleteById(id);
    }

    @Override
        public void deletePushListConfigListByIds(List<Long> ids) {
        // 删除
        pushListConfigMapper.deleteByIds(ids);
        }


    private void validatePushListConfigExists(Long id) {
        if (pushListConfigMapper.selectById(id) == null) {
            throw exception(PUSH_LIST_CONFIG_NOT_EXISTS);
        }
    }

    @Override
    public PushListConfigDO getPushListConfig(Long id) {
        return pushListConfigMapper.selectById(id);
    }

    @Override
    public PageResult<PushListConfigDO> getPushListConfigPage(PushListConfigPageReqVO pageReqVO) {
        return pushListConfigMapper.selectPage(pageReqVO);
    }

}